<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Admin;
class Login extends Controller
{
    public function index()
    {
        // 临时关闭当前模板的布局功能
        $this->view->engine->layout(false);

        if(request()->isPost()){
            $this->check(input('code'));
        	$admin = new Admin();
        	$data = input('post.');
        	$num = $admin->login($data);
        	if($num == 1){
        		$this->error('用户不存在！');
        	} elseif($num == 2){
        		$this->success('登录成功！',url('index/index'));
        	} elseif($num == 3){
        		$this->error('密码错误！');
        	} elseif ($num == 4){
                $this->error('验证码错误');
            }
        	return;
        }
        return view();
    }

    // 验证码检测
    public function check($code='')
    {
        if (!captcha_check($code)) {
            $this->error('验证码错误');
        } else {
            return true;
        }
    }

}
